﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WCS.Infrastructure.Attr;
using WCS.Infrastructure.Dto.Request.Organization;
using WCS.Service.Instance;
using WCS.Service.Interface;

namespace WCS.Api.Admin.Controllers
{
    /// <summary>
    /// 短信服务模块
    /// </summary>
    public class SmsController : BaseController
    {
        private readonly IConfiguration _configuration;
        private readonly ISmsService _smsService;
        public SmsController(IUserService userService, IConfiguration configuration, ISmsService smsService) : base(userService)
        {
            _configuration = configuration;
            _smsService = smsService;
        }

        /// <summary>
        /// 发送验证码短信
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <returns></returns>
        [HttpGet]
        [ActionLog(Action = "发送验证码短信", Group = "短信服务")]
        [AllowAnonymous]
        public async Task<IActionResult> SendVerificationCode(string phoneNumber)
        {
            var result = await _smsService.SendVerificationCodeAsync(phoneNumber);
            return Ok(result);
        }

        /// <summary>
        /// 校验验证码
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        [HttpGet]
        [ActionLog(Action = "校验验证码", Group = "短信服务")]
        [AllowAnonymous]
        public async Task<IActionResult> VerifyCode(string phoneNumber, string code)
        {
            var result = await _smsService.VerifyCodeAsync(phoneNumber, code);
            return Ok(result);
        }

        /// <summary>
        /// 发送带用户名和密码的短信
        /// </summary>
        /// <param name="phoneNumber"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        [HttpGet]
        [ActionLog(Action = "发送带用户名和密码的短信", Group = "短信服务")]
        [AllowAnonymous]
        public IActionResult SendSmsPhoneAndPassword(string phoneNumber, string userName, string password)
        {
            var result = _smsService.SendSmsPhoneAndPassword(phoneNumber, userName, password);
            return Ok(result);
        }


    }
}
